package com.itheima.hashset1;

import java.util.Objects;

public class Student {

    private String name;
    private int age;
    private int id;
    private String address;

    public Student() {
    }

    public Student(String name, int age, int id, String address) {
        this.name = name;
        this.age = age;
        this.id = id;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public boolean equals(Object o) {
        //1.如果是自己和自己比较，直接返回true
        if (this == o) return true;
        //2.如果o为空，或者o不是Student类型，直接返回false
        if (o == null || getClass() != o.getClass()) return false;
        //3.如果o不是空，并且o是Student类型，则进行属性比较
        Student student = (Student) o;
        return age == student.age && id == student.id && Objects.equals(name, student.name) && Objects.equals(address, student.address);
    }

    @Override
    public int hashCode() {
        //包装了不同的学生对象，如果内容一样返回的hash值是一样的
        return Objects.hash(name, age, id, address);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                ", address='" + address + '\'' +
                '}' + "\n";
    }
}
